/**
 * Created by Taller on 17/3/1.
 */
var menuData = [
    {name: 'John Doen'},
    {name: 'John 2'},
    {name: 'John 3'},
    {name: 'John 4'},
    {name: 'John 5'},
    {name: 'John 6'},
    {name: 'John 7'},
    {name: 'John 8'},
    {name: 'John 9'},
    {name: 'John 21'},
    {name: 'John 31'},
    {name: 'John 22'},
    {name: 'John 32'},
    {name: 'John 23'},
    {name: 'John 33'},
    {name: 'John 24'},
    {name: 'John 34'},
];
var menuData2 = [
    {name: 'John 111'},
    {name: 'John 2222'},
    {name: 'John 2223'},
    {name: 'John 2224'},
    {name: 'John 225'},
    {name: 'John 3336'},
    {name: 'John 4447'},
    {name: 'John 5558'},
    {name: 'John 966'},
    {name: 'John 27771'},
    {name: 'John 3881'},
    {name: 'John 24322'},
    {name: 'John 234'},
    {name: 'John 2rew3'},
    {name: 'John 3wer3'},
    {name: 'John 2fdsewr4'},
    {name: 'John 3sdf4'},
];


initTemplate('#list-menu-template','#list-menu',menuData,0);

//操作控件
var menuContent = $$('.list-menu-page');
//下拉刷新
menuContent.on('refresh', function (e) {
    setTimeout("initRefresh()",1500);
});
function initRefresh() {
    initTemplate('#list-menu-template','#list-menu',menuData,0);
    app.pullToRefreshDone();
}

//上拉加载
var loading = false;    //加载状态
var index = 1;          //页码
var maxPage = 5;        //最多加载页数
menuContent.on('infinite', function () {
    if (loading) return;
    loading = true;
    if(index == 5){
        app.detachInfiniteScroll(menuContent);
        $$('.infinite-scroll-preloader').remove();
        return;
    }
    setTimeout(function () {
        initTemplate('#list-menu-template','#list-menu',menuData2,1);
        loading = false;
        index +=1;
    },1000);
});